<template>
  <div>

    <el-container>

      <el-header class="layout-header">

<!--        <h1 style="color: aliceblue;float: right;margin-right: 10px;font-size: 17px">{{user.username}}</h1>
        <el-avatar icon="el-icon-user-solid" style="margin-top: 10px;float: right;margin-right: 10px"></el-avatar>-->
        <el-dropdown trigger="click" style="position: absolute;right: 40px;top: 10px">
          <h1 style="color: aliceblue;font-size: 19px;font-weight: bold;">
<!--            <el-icon><User /></el-icon>-->
            <el-avatar icon="el-icon-user-solid"></el-avatar>
            <span style="margin:0 5px;position: relative;top: 7px">{{user.username}}</span>
            <el-icon style="top: 8px"><arrow-down/></el-icon>
          </h1>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>

        <img src="" style="width: 120px;height: 40px;position: absolute;top: 10px">
        <h1 style="color: aliceblue;margin-left: 10%; ">OA协调办公系统</h1>
      </el-header>

      <el-container class="layout-body">
        <el-aside class="layout-aside" style="width: 200px">
          <el-menu
              background-color="#545c64"
              router
              :default-active="this.$router.currentRoute.path"
              text-color="#fff"
              active-text-color="#ffd04b"
              class="el-menu-vertical-demo"
              unique-opened>
            <el-sub-menu index="1">
              <template #title>
                <el-icon><Avatar /></el-icon><span>系统用户管理</span>
              </template>
              <el-menu-item index="/user">员工管理</el-menu-item>
              <el-menu-item index="/dept">部门管理</el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="2">
              <template #title>
                <el-icon><Stamp /></el-icon><span>印章管理</span>
              </template>
              <el-menu-item index="/stamp">印章管理</el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="3">
              <template #title>
                <el-icon><Briefcase /></el-icon><span>考勤管理</span>
              </template>
              <el-menu-item index="/attendance">考勤管理</el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="4">
              <template #title>
                <el-icon><List /></el-icon><span>公告文本</span>
              </template>
              <el-menu-item index="/anno">公告管理</el-menu-item>
            </el-sub-menu>
          </el-menu>
        </el-aside>
        <el-main style="background-color: rgba(245, 246, 249, 1);">
          <router-view/>
        </el-main>
      </el-container>
    </el-container>

  </div>
</template>

<script setup>
import {ref} from "vue";

//获取当前登录人
const user = ref(getUser());

//退出登录
const logout = () => {
  if(confirm("确认退出登录吗?")){
    //退出时要清除当前登录的用户数据
    localStorage.removeItem("user");
    //清除token
    //localStorage.removeItem("token");
    // 跳转回登录页
    window.location.href = "/login";
    //清空刚刚取出来的数据
    user.value = '';
  }
}


// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

/*export default {
  name: 'HomeView',
  components: {},
}*/
</script>
<style>
.layout-header {
  background-color: #545c64;
  line-height: 60px;

}

.layout-body {
  position: absolute;
  top: 60px;
  bottom: 0;
  right: 0;
  left: 0;
}

.layout-aside {
  background-color: #545c64;
}

.el-menu-item.is-active {
  background: #3d3c3c !important;
}
</style>